#!/usr/bin/env python3
import os
import json

class Config:
    def __init__(self):
        self.config_file = 'config.json'
        self.log_dir = None
        self.client_lite = 1
        self._load_config()

    def _load_config(self):
        if os.path.exists(self.config_file):
            try:
                with open(self.config_file, 'r', encoding='utf-8') as f:
                    config = json.load(f)
                    self.log_dir = config.get('log_dir')
            except Exception as e:
                print(f'加载配置文件失败: {str(e)}')

    def _save_config(self):
        config = {
            'log_dir': self.log_dir
        }
        try:
            with open(self.config_file, 'w', encoding='utf-8') as f:
                json.dump(config, f, indent=4)
            return True
        except Exception as e:
            print(f'保存配置文件失败: {str(e)}')
            return False

    def set_log_dir(self, log_dir):
        self.log_dir = log_dir
        return self._save_config()

    def get_log_dir(self):
        return self.log_dir